
(function(window,document,Laya){
	var __un=Laya.un,__uns=Laya.uns,__static=Laya.static,__class=Laya.class,__getset=Laya.getset,__newvec=Laya.__newvec;

	var Button=laya.ui.Button,Camera=laya.d3.core.Camera,DirectionLight=laya.d3.core.light.DirectionLight;
	var IDEAPIS=laya.ide.managers.IDEAPIS,Node=laya.display.Node,Scene3DPlayer=d3.Scene3DPlayer,SkyBoxMaterial=laya.d3.core.material.SkyBoxMaterial;
	var Vector3=laya.d3.math.Vector3,Vector4=laya.d3.math.Vector4;
	//
	//class component.MScene3DPlayer extends d3.Scene3DPlayer
	var MScene3DPlayer=(function(_super){
		function MScene3DPlayer(){
			MScene3DPlayer.__super.call(this);
		}

		__class(MScene3DPlayer,'component.MScene3DPlayer',_super);
		var __proto=MScene3DPlayer.prototype;
		__proto.preview=function(){
			if(this.comXml){
				var sceneNode=IDEAPIS.GetNodeByNodeRefer("@node:"+this.comXml.compId);
				sceneNode.cameraEnable=!sceneNode.cameraEnable;
				sceneNode.comXml.props.cameraEnable=sceneNode.cameraEnable;
				var mCamera=MScene3DPlayer.getMCamera(sceneNode);
				if(mCamera){
					mCamera.active=!sceneNode.cameraEnable;
					mCamera.comXml.props.activeValue=mCamera.active;
				}
				IDEAPIS.getCurDesign().change(true);
			}
		}

		__getset(0,__proto,'fogColorValue',null,function(_color){
			if(Array.isArray(_color)){
				var _tmp=new Vector3();
				_tmp.fromArray(_color);
				this.fogColor=_tmp;
			}
		});

		__getset(0,__proto,'ambientColorValue',null,function(_color){
			if(Array.isArray(_color)){
				var _tmp=new Vector3();
				_tmp.fromArray(_color);
				this.ambientColor=_tmp;
			}
		});

		MScene3DPlayer.getMCamera=function(node){
			if(node && node._children.length>0){
				for (var i=0,len=node._children.length;i < len;i++){
					var object=node._children[i];
					if((object instanceof component.MCamera )){
						return object;
					};
					var c=MScene3DPlayer.getMCamera(object);
					if(c)return c;
				}
			}
			return null;
		}

		return MScene3DPlayer;
	})(Scene3DPlayer)


	//class component.MCamera extends laya.d3.core.Camera
	var MCamera=(function(_super){
		function MCamera(){
			this._target=null;
			this.__active=false;
			MCamera.__super.call(this);
		}

		__class(MCamera,'component.MCamera',_super);
		var __proto=MCamera.prototype;
		// node && node.scene.camera.active=!isActive;
		__proto.getSceneNode=function(comXml){
			if(!comXml){
				return null;
			};
			var parentNodeId="@node:"+comXml.nodeParent;
			var parentNode=IDEAPIS.GetNodeByNodeRefer(parentNodeId);
			if(!parentNode){
				return null;
			}
			if(parentNode.comXml && parentNode.comXml.type=="Scene3D2"){
				return parentNode;
			}
			return this.getSceneNode(parentNode.comXml);
		}

		//laya.ide.managers.IDEAPIS.GetNodeByNodeRefer("@node:199")
		__getset(0,__proto,'rotationEuler',null,function(_rotate){
			if(Array.isArray(_rotate)){
				this.comXml.props.rotationEuler[0]=_rotate[0];
				this.comXml.props.rotationEuler[1]=_rotate[1];
				this.comXml.props.rotationEuler[2]=_rotate[2];
				var _tmp=new Vector3();
				_tmp.fromArray(_rotate);
				this.transform.rotationEuler=_tmp;
			}
		});

		/**
		*是否激活摄像机
		*@param isActive
		*/
		__getset(0,__proto,'activeValue',null,function(isActive){
			this.active=isActive;
			var node=IDEAPIS.GetNodeByNodeRefer(this._target);
			if(!node){
				return;
			}
			node && this.transform.lookAt(node.transform.position,Vector3.Up);
		});

		/**
		*摄像机背景颜色
		*@param _color
		*/
		__getset(0,__proto,'clearColorValue',null,function(_color){
			if(!this.clearColor){
				this.clearColor=new Vector4();
			}
			if(Array.isArray(_color)){
				this.clearColor.fromArray(_color);
			}
		});

		__getset(0,__proto,'position',null,function(_pos){
			if(Array.isArray(_pos)){
				this.comXml.props.x=_pos[0]*100;
				this.comXml.props.y=_pos[1]*-100;
				this.comXml.props.z=_pos[2]*100;
				this.transform.localPosition.fromArray(_pos);
				this.transform.localPosition=this.transform.localPosition;
				var node=IDEAPIS.GetNodeByNodeRefer(this._target);
				if(!node){
					return;
				}
				this.transform.lookAt(node.transform.position,Vector3.Up);
			}
		});

		/**
		*设置天空盒skin
		*/
		__getset(0,__proto,'skyBox',null,function(skin){
			this.skyboxMaterial=SkyBoxMaterial.load(IDEAPIS.assetsPath+"/"+skin);
		});

		/**
		*设置摄像机朝向的目标
		*@param nodeId
		*/
		__getset(0,__proto,'target',null,function(nodeId){
			var node=IDEAPIS.GetNodeByNodeRefer(nodeId);
			node && this.transform.lookAt(node.transform.position,Vector3.Up);
			this._target=nodeId;
		});

		return MCamera;
	})(Camera)


	//class component.MDirectionLight extends laya.d3.core.light.DirectionLight
	var MDirectionLight=(function(_super){
		function MDirectionLight(){
			MDirectionLight.__super.call(this);
		}

		__class(MDirectionLight,'component.MDirectionLight',_super);
		var __proto=MDirectionLight.prototype;
		__proto._prepareToScene=function(){
			if(!this.scene){
				return false;
			}
			return _super.prototype._prepareToScene.call(this);
		}

		__getset(0,__proto,'colorValue',null,function(_color){
			if(Array.isArray(_color)){
				this.color.fromArray(_color);
			}
			console.log("color = "+_color);
		});

		__getset(0,__proto,'rotationEuler',null,function(_rotate){
			console.warn("rotationEuler = "+_rotate);
			if(Array.isArray(_rotate)){
				var _tmp=new Vector3();
				_tmp.fromArray(_rotate);
				this.transform.rotationEuler=_tmp;
			}
		});

		return MDirectionLight;
	})(DirectionLight)


	//class component.Test extends laya.ui.Button
	var Test=(function(_super){
		function Test(){
			this.t=1;
			Test.__super.call(this);
			this.init("123");
			new MCamera();
			new MDirectionLight();
			new MScene3DPlayer();
		}

		__class(Test,'component.Test',_super);
		var __proto=Test.prototype;
		__proto.init=function(d){}
		return Test;
	})(Button)



})(window,document,Laya);
